#pragma once
#include "abstractstate.h"

#include <chrono>
#define NOW std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count()
#define TIMEOUT(us) virtual void check_timeout() override;uint64_t timeoutUs = us; uint64_t startTimestamp = NOW;
#define CHECK_TIMEOUT(src,dst) void src::check_timeout() { \
if(NOW - startTimestamp > timeoutUs) { trans_to<dst>(); } }


class State1 : public AbstractState
{
public:
    State1(std::shared_ptr<std::shared_ptr<AbstractState>> currentStatePtr) :AbstractState(currentStatePtr) {}
    virtual int update() override;

    TIMEOUT(5 * 1000 * 1000);
};

class State2 : public AbstractState
{
public:
    State2(std::shared_ptr<std::shared_ptr<AbstractState>> currentStatePtr) :AbstractState(currentStatePtr) {}
    virtual int update() override;

    TIMEOUT(2 * 1000 * 1000);
};

class State3 : public AbstractState
{
public:
    State3(std::shared_ptr<std::shared_ptr<AbstractState>> currentStatePtr) :AbstractState(currentStatePtr) {}
    virtual int update() override;

    TIMEOUT(3 * 1000 * 1000);
};

class State4 : public AbstractState
{
public:
    State4(std::shared_ptr<std::shared_ptr<AbstractState>> currentStatePtr) :AbstractState(currentStatePtr)
    {
        isEndState = true;
    }
};
